// 登录界面
let loginboxshadow = document.querySelector(".login-box-shadow")
let txtbox = document.querySelector(".txt-box");
let tel = document.querySelector("#tel");
let dropdownbox = document.querySelector(".dropdownbox");
let userpassword = document.querySelector("#password");
let identify = document.querySelector("#identify");
let send = document.querySelector(".send");
let formbtns = document.querySelectorAll(".form-btn button");
let loginbtn = document.querySelector(".login-btn");
let indexbtn = document.querySelector(".index-btn");
// 注册界面
let loginboxregister = document.querySelector(".login-box-register")
let phone = document.querySelector("#phone");
let iden = document.querySelector("#iden");
let idenbtn = document.querySelector("#iden-btn");
let pass = document.querySelector("#pass");
let agree = document.querySelector(".agree");
let nextbtn = document.querySelector("#next");
// console.log(indexbtn);
// 注册按钮
indexbtn.onclick = function(){
    console.log(111);
    loginboxregister.style.display =" block";
}
// 输入的正则格式验证
// let isuserphone = false;
// phone.onchange = function(){
//     let res = /^1|[0-9]{8}$/;
//     if(res.test(this.value)){
//         isuserphone = true;
//     }else{
//         isuserphone = false;
//         alert("请输入正确的手机号格式")
//     }
// }
// 下一步按钮
nextbtn.onclick = function(){
    let username  = phone.value;
    let password = pass.value;
    console.log(username,password);
    axios
    .get(regAPI,{params:{
        username,
        password
    }
    })
    .then(({data})=>{
        console.log(data);
        alert(data.msg);
        if(data.code == 1){
            location.reload();
        }
    })
    phone.value = '';
    pass.value = '';
    return false;
}

// 登录按钮
loginbtn.onclick = function(){
    let username = tel.value;
    let password = userpassword.value;
    axios
        .get(loginAPI,{params:{
            username,
            password
        }
    })
        .then(({data}) =>{
            console.log(data);
            // alert(data.msg)
            console.log(data.data.id);
            if(data.code == 1){
                localStorage.setItem("uid",data.data.id);
                console.log(data,data.id);
                localStorage.setItem("usertel",data.data.username);
                localStorage.setItem("token",data.data.token);
                location.href = "../index.html";
            }else{
                alert("用户名不存在")
            }
        })
        return false;
}
